package com.danceforyou.common.restful;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

import com.danceforyou.common.restful.exception.BizException;

public class ResponseT<T> implements Serializable {
	
	private static final long serialVersionUID = 5369667759174813049L;
	
	private String code;
    private String msg;
    private String debugMsg;
    private long timestamp;
    private T bizData;
    
    public ResponseT() {
        this.timestamp = System.currentTimeMillis();
    }

    public ResponseT(RtnCodeEnum rtnCode) {
        this.code = rtnCode.getCode();
        this.msg = rtnCode.getMsg();
        this.timestamp = System.currentTimeMillis();
    }

    public ResponseT(BizException bizException) {
        this(bizException, false);
    }

    public ResponseT(BizException bizException, boolean isDebug) {
        this.code = bizException.getCode();
        this.msg = bizException.getMsg();
        this.timestamp = System.currentTimeMillis();
        if (isDebug) {
            StringWriter writer = new StringWriter();
            bizException.printStackTrace(new PrintWriter(writer, true));
            this.debugMsg = writer.toString();
        }
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public String getDebugMsg() {
        return debugMsg;
    }

    public void setDebugMsg(String debugMsg) {
        this.debugMsg = debugMsg;
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public T getBizData() {
        return bizData;
    }

    public void setBizData(T bizData) {
        this.bizData = bizData;
    }
}
